package cn.diancan.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

 



public class ProcessUtils {
	
	 public static String getHdSerialInfo(String cmd) {

		  String line = "";
		  String HdSerial = "";//记录硬盘序列号

		  try {

		   Process proces = Runtime.getRuntime().exec(cmd);//获取命令行参数
		   BufferedReader buffreader = new BufferedReader(
		     new InputStreamReader(proces.getInputStream()));

		   while ((line = buffreader.readLine()) != null) {

		    /*if (line.indexOf("卷的序列号是 ") != -1) {  //读取参数并获取硬盘序列号

		     HdSerial = line.substring(line.indexOf("卷的序列号是 ")
		       + "卷的序列号是 ".length(), line.length());
		     break;
		     // System.out.println(HdSerial);
		    }*/
			   HdSerial+=line+"\n";
		   }

		  } catch (IOException e) {
		   // TODO Auto-generated catch block
		   e.printStackTrace();
		  }

		  return HdSerial;//返回硬盘序列号
	}
	
	public static void main(String[] args) {
		String s1= getHdSerialInfo("cmd /c dir c:");
		System.out.println(s1);
		String s2= getHdSerialInfo("ipconfig");
		System.out.println(s2);
		
	}
	 
}